package com.lksy.web.controller.system;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lksy.web.controller.BaseController;

/**
 * 
 * @author jzx
 * @date 2016-08-02 11:05:40
 *
 */
@Controller
@RequestMapping("desk")
public class SystemDeskController extends BaseController {

	@RequestMapping("/admin")
	public @ResponseBody Map<String, Object> index(HttpServletRequest request) {
		 Map<String, Object> modelMap = new HashMap<String, Object>();  
		 pushSystemStatus(request, modelMap);
		return modelMap;
	}

	private void pushSystemStatus(HttpServletRequest request, Map<String, Object> model) {
		float freeMemory = (float) Runtime.getRuntime().freeMemory();
		float totalMemory = (float) Runtime.getRuntime().totalMemory();
		float usedMemory = (totalMemory - freeMemory);
		float memPercent = Math.round(freeMemory / totalMemory * 100);
		String os = System.getProperty("os.name");
		String javaVersion = System.getProperty("java.version");

		model.put("freeMemory", freeMemory);
		model.put("totalMemory", totalMemory / 1024 / 1024);
		model.put("usedMemory", usedMemory / 1024 / 1024);
		model.put("memPercent", memPercent);
		model.put("os", os);
		model.put("javaVersion", javaVersion);
	}
}
